/**
 * 
 */
package com.taobao.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 * @author tianping.czp
 *
 */
@Aspect
public class MyTestAdvice {

	
	@Before("com.taobao.spring.aop.MyTestAspect.methodNamePrint()")
	public void beforeMethod(JoinPoint jp){
		System.out.println("before method");
		System.out.println(jp.getTarget().toString());
	}
	
	@AfterReturning(pointcut="execution (* com.taobao.spring.aop.TargetObject.method3(..))",returning = "relVal")
	public void afterMethod(JoinPoint jp,Object relVal){
		System.out.println("after method:" + relVal);
		System.out.println(jp.getTarget().toString());
	}
	
	@Around("execution (* com.taobao.spring.aop.TargetObject.method2(..))&&" + "args(pattern)")
	public Object aroundMethod(ProceedingJoinPoint pjp,String pattern) throws Throwable {
		
	    // start stopwatch
		System.out.println("around start");
		System.out.println("pattern :" + pattern);
	    Object retVal = pjp.proceed(new Object[]{pattern});
	    // stop stopwatch
	    System.out.println("around end");
	    return retVal;
	}
}
